package com.yf.thumbbackend.controller;

import com.yf.thumbbackend.common.BaseResponse;
import com.yf.thumbbackend.common.ResultUtils;
import com.yf.thumbbackend.entity.Blog;
import com.yf.thumbbackend.entity.vo.BlogVO;
import com.yf.thumbbackend.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 随风
 * @date 2025/4/19 14:58
 * @description BlogController
 */
@RestController
@RequestMapping("blog")
public class BlogController {
    @Resource
    private BlogService blogService;

    /**
     * 根据id获取博客
     * @param id
     * @param request
     * @return
     */
    @GetMapping("/get")
    public BaseResponse<BlogVO> getBlogById(Long id, HttpServletRequest request){
        BlogVO blogVO = blogService.getBlogById(id,request);
        return ResultUtils.success(blogVO);

    };

    @GetMapping("/list")
    public BaseResponse<List<BlogVO>> getBlogVoList(HttpServletRequest request){
        List<Blog> list = this.blogService.list();

       List<BlogVO> blogVOList =  blogService.getBlogVoList(list,request);
       return ResultUtils.success(blogVOList);
    }




}
